import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src'),
    },
  },
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
      },
    },
  },
  server: {
    port: 3000,
    host: '0.0.0.0', // 允许局域网访问
    open: false,
    cors: true,
    proxy: {
      '/api': {
        // target: 'http://172.16.103.226:8088', // 后端服务地址
        target: 'http://1.95.207.63:8088', // 后端服务地址
        // target: 'http://172.18.196.122:8088', // 后端服务地址
        // target: 'http://47.108.158.23:20000',
        // target: 'http://47.108.158.23:19014',
        changeOrigin: true, // 允许跨域
        rewrite: (path) => path.replace(/^\/api/, ''), // 路径重写，去除 /api 前缀
        secure: false, // 如果是 https 需要设置为 false
      },
    },
  },
})
